package com.dengdai.applibrary.utils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.dengdai.applibrary.config.ViewInfo;
import com.dengdai.applibrary.entity.DTO;
import com.dengdai.applibrary.interfaces.ActivityInterface;

import java.io.Serializable;

/**
 * @说明 业务操作
 * @作者 LY
 * @时间 15/12/15 13:16
 * @版权 Copyright(c) 2015 LY-版权所有
 */
public class OperationUtils {
    /**
     * 激活Activity组件意图
     */
    private Intent mIntent = new Intent();
    /***
     * 上下文
     **/
    private Activity mContext = null;

    public OperationUtils(Activity activity) {
        this.mContext = activity;
    }

    /**
     * 跳转activity
     *
     * @param c 跳转对象
     */
    public void forward(Class c, int animType) {
        forward(c.getName(), animType);
    }

    /**
     * 跳转Activity
     *
     * @param className 需要跳转至的Activity名称
     */
    public void forward(String className) {
        forward(className, ActivityInterface.ANIMATION_NONE);
    }

    /**
     * 跳转Activity
     *
     * @param className 需要跳转至的Activity名称
     * @param animType  动画类型IBaseActivity.LEFT_RIGHT/TOP_BOTTOM/FADE_IN_OUT
     */
    public void forward(String className, int animType) {
        mIntent.setClassName(mContext, className);
        mIntent.putExtra(ActivityInterface.ANIMATION_TYPE, animType);
        mContext.startActivity(mIntent);
        switch (animType) {
            case ActivityInterface.ANIMATION_LEFT_RIGHT:
                int inLFAnim = BaseViewUtils.gainResId(mContext, BaseViewUtils.ANIM, ViewInfo.SLIDE_RIGHT_IN);
                int outLFAnim = BaseViewUtils.gainResId(mContext, BaseViewUtils.ANIM, ViewInfo.SLIDE_REMAIN);
                mContext.overridePendingTransition(inLFAnim, outLFAnim);
                break;
            case ActivityInterface.ANIMATION_TOP_BOTTOM:
                int inTBAnim = BaseViewUtils.gainResId(mContext, BaseViewUtils.ANIM, ViewInfo.PUSH_UP_IN);
                int outTBAnim = BaseViewUtils.gainResId(mContext, BaseViewUtils.ANIM, ViewInfo.PUSH_UP_OUT);
                mContext.overridePendingTransition(inTBAnim, outTBAnim);
                break;
            case ActivityInterface.ANIMATION_FADE_IN_OUT:
                int inFAnim = BaseViewUtils.gainResId(mContext, BaseViewUtils.ANIM, ViewInfo.FADE_IN);
                int outFAnim = BaseViewUtils.gainResId(mContext, BaseViewUtils.ANIM, ViewInfo.FADE_OUT);
                mContext.overridePendingTransition(inFAnim, outFAnim);
                break;
        }
    }

    /**
     * 设置传递参数
     *
     * @param bundle 数据
     */
    public void addBundle(Bundle bundle) {
        mIntent.putExtras(bundle);
    }

    /**
     * 设置传递参数
     *
     * @param key   参数key
     * @param value 数据传输对象
     */
    public void addParameter(String key, DTO value) {
        mIntent.putExtra(key, value);
    }

    /**
     * 设置传递参数
     *
     * @param key   参数key
     * @param value 数据传输对象
     */
    public void addParameter(String key, Bundle value) {
        mIntent.putExtra(key, value);
    }

    /**
     * 设置传递参数
     *
     * @param key   参数key
     * @param value 数据传输对象
     */
    public void addParameter(String key, Serializable value) {
        mIntent.putExtra(key, value);
    }

    /**
     * 设置传递参数
     *
     * @param key   参数key
     * @param value 数据传输对象
     */
    public void addParameter(String key, String value) {
        mIntent.putExtra(key, value);
    }


}
